﻿#include <QTimer>
#include <QFile>
#include "UTearPointState.h"

UTearPointState::UTearPointState(QWidget *parent)
{
	ui.setupUi(this);
	m_sNormalLamp = "min-width:20px;min-height:20px;"
		"max-width:20px;max-height:20px;"
		"border-radius:10px;border:1px solid black;"
		"background:rgb(120, 120, 120);";
	m_sWorkLamp = "min-width:20px;min-height:20px;"
		"max-width:20px;max-height:20px;"
		"border-radius:10px;border:1px solid black;"
		"background:rgb(0, 255, 0);";
	m_sAlarmLamp = "min-width:20px;min-height:20px;"
		"max-width:20px;max-height:20px;"
		"border-radius:10px;border:1px solid black;"
		"background:rgb(255, 0, 0);";
	m_sWarningLamp = "min-width:20px;min-height:20px;"
		"max-width:20px;max-height:20px;"
		"border-radius:10px;border:1px solid black;"
		"background:rgb(255,255,0);";
	setStyleSheetFile();
	//配置定时器
	m_pTimer = new QTimer(this);
	m_pTimer->setTimerType(Qt::TimerType::PreciseTimer);
	connect(m_pTimer, &QTimer::timeout, this, &UTearPointState::slotDataRefresh);
}

UTearPointState::~UTearPointState()
{}

void UTearPointState::setStyleSheetFile()
{
	QString sQssPath = ":/qss/styleSheet.css";
	QFile qss(sQssPath);
	qss.open(QFile::ReadOnly);
	this->setStyleSheet(qss.readAll());
}

void UTearPointState::slotDataRefresh()
{
	if (isVisible())
	{
		m_pBeltData->m_pMutex->lock();
		//撕裂状态
		if (m_pBeltData->m_nAlarmType == 0)
		{
			ui.labelTearState->setStyleSheet(m_sWorkLamp);
		}
		else
		{
			ui.labelTearState->setStyleSheet(m_sAlarmLamp);
		}
		//摄像头状态
		if (m_pBeltData->m_nCamerState == 0)
		{
			ui.labelCamerState->setStyleSheet(m_sWorkLamp);
		}
		else
		{
			ui.labelCamerState->setStyleSheet(m_sAlarmLamp);
		}
		//算法状态
		//if (m_pBeltData->m_nTearAlgState == 0)
		if(1)
		{
			ui.labelTearAlgState->setStyleSheet(m_sWorkLamp);
		}
		else
		{
			ui.labelTearAlgState->setStyleSheet(m_sAlarmLamp);
		}
		//皮带启停信号
		if (m_pBeltData->m_bBeltWork)
		{
			ui.labelBeltState->setStyleSheet(m_sWorkLamp);
		}
		else
		{
			ui.labelBeltState->setStyleSheet(m_sNormalLamp);
		}
		ui.labelPointName->setText(m_pBeltData->m_sName);
		ui.labelKaMax->setText(QString::number(m_pBeltData->m_dKaMax));
		ui.labelMaskSum->setText(QString::number(m_pBeltData->m_nMaskSum));
		ui.labelLineHight->setText(QString::number(m_pBeltData->m_nLineHight));
		m_pBeltData->m_pMutex->unlock();
	}
}
